import numpy 
from matplotlib import pyplot,ticker
import datetime
import csv

def toaxis(f):
    with open(f) as f:
        reader = csv.reader(f)
        next(reader)
        x = []
        y1 = []
        y2 = []
        y3 = []
        v = []
        for i in reader:
            x.append (datetime.datetime.strptime(i[0], "%Y-%m-%d %H:%M:%S"))
        
            y1.append (None if i[1] == "" or i[1] == "none" else int(float(i[1])))
            y2.append (None if i[2] == "" or i[2] == "none" else int(float(i[2])))
            y3.append (None if i[3] == "" or i[3] == "none" else int(float(i[3])))
            v.append (None if i[4] == "" or i[4] == "none" else int(float(i[4])))

    # return numpy.array(x),numpy.array(y1),numpy.array(y2),numpy.array(y3),numpy.array(v)
    return x,y1,y2,y3,v

def vvfig(x1,y1,x2,y2,tittle,label1,label2,axis_x,axis_y):
    # fig = pyplot.figure()
    pyplot.rcParams["font.family"]="SimHei" #中文
    # ax = fig.add_subplot(111)
    # ax2 = ax1.twinx()
    # ax = pyplot.subplot(111)
 
    pyplot.title(tittle)  #设置标题 

    pyplot.scatter(x1,y1,s=5,c='r',marker='o',label=label1,alpha=0.3,edgecolors='none')
    pyplot.scatter(x2,y2,s=5,c='b',marker='o',label=label2,alpha=0.3,edgecolors='none')

    pyplot.xlabel(axis_x)  
    pyplot.ylabel(axis_y) 

    pyplot.xticks(rotation="45")

    # plt.xticks(range(2008, 2020, 1))
    # pyplot.yticks(range(0, 7500, 1000))

    # ax.ticklabel_format(useOffset=False,style='plain')
    # ax=pyplot.gca() #ax为两条坐标轴的实例
    # ax.get_yaxis().get_major_formatter().set_useOffset(False)
    # y_formatter = ticker.ScalarFormatter(useOffset=False,useMathText=False)
    # ax.yaxis.set_major_formatter(y_formatter)

    # x_major_locator=pyplot.MultipleLocator(200) #x轴的刻度间隔,并存在变量里
    # y_major_locator=pyplot.MultipleLocator(100) 
    
    # ax.xaxis.set_major_locator(x_major_locator) #把x轴的主刻度设置为1的倍数
    # ax.yaxis.set_major_locator(y_major_locator)

    pyplot.legend()  #设置图标  
    pyplot.show()  

def basefig(d1,d2,tittle,label1,label2,axis_x,axis_y):
    # fig = pyplot.figure()
    pyplot.rcParams["font.family"]="SimHei" #中文
    # ax = fig.add_subplot(111)
    # ax2 = ax1.twinx()
    # ax = pyplot.subplot(111)
 
    pyplot.title(tittle)  #设置标题 

    pyplot.scatter(d1[0],d1[1],s=6,c='r',marker='o',label=label1,alpha=0.1,edgecolors='none')
    pyplot.scatter(d1[0],d1[2],s=6,c='r',marker='o',alpha=0.1,edgecolors='none')
    pyplot.scatter(d1[0],d1[3],s=6,c='r',marker='o',alpha=0.1,edgecolors='none')
    pyplot.scatter(d2[0],d2[1],s=6,c='b',marker='o',label=label2,alpha=0.1,edgecolors='none')
    pyplot.scatter(d2[0],d2[2],s=6,c='b',marker='o',alpha=0.1,edgecolors='none')
    pyplot.scatter(d2[0],d2[3],s=6,c='b',marker='o',alpha=0.1,edgecolors='none')

    pyplot.xlabel(axis_x)  
    pyplot.ylabel(axis_y) 

    pyplot.xticks(rotation="45")

    # plt.xticks(range(2008, 2020, 1))
    # pyplot.yticks(range(0, 7500, 1000))

    # ax.ticklabel_format(useOffset=False,style='plain')
    # ax=pyplot.gca() #ax为两条坐标轴的实例
    # ax.get_yaxis().get_major_formatter().set_useOffset(False)
    # y_formatter = ticker.ScalarFormatter(useOffset=False,useMathText=False)
    # ax.yaxis.set_major_formatter(y_formatter)

    # x_major_locator=pyplot.MultipleLocator(200) #x轴的刻度间隔,并存在变量里
    # y_major_locator=pyplot.MultipleLocator(100) 
    
    # ax.xaxis.set_major_locator(x_major_locator) #把x轴的主刻度设置为1的倍数
    # ax.yaxis.set_major_locator(y_major_locator)

    pyplot.legend()  #设置图标  
    pyplot.show()  
# ax3 = ax1.twinx()
# ax3.scatter(x,y1,c = 'b', marker = 'o')


if __name__ == '__main__':

    filename1 = 'CEILO_09_sorted.csv'
    filename2 = 'CEILO_10_sorted.csv'
    d1 = toaxis(filename1)
    d2 = toaxis(filename2)
    # print(type(d1[0]))
    # basefig(d1,d2,"东端云底高对比","CL31","CMBE80B","TIME","云高")
    vvfig(d1[0],d1[4],d2[0],d2[4],"西端垂直能见度对比","CL31","CMBE80B","TIME","VV")